dojo.provide("miaigo.model.utils");

/* Return Value:
 * {
 *   west : {x:x1, y:y1} | null,
 *   north: {x:x2, y:y2} | null,
 *   east : {x:x3. y:y3} | null,
 *   south: {x:x4, y:x4} | null
 * }
 * if a field is null or undefined, this means there is no available point
 * on this direction (i.e. at the board edge)
 */
miaigo.model.utils.adjacentPoints = function(/* {x, y} */point, /* Number */boardSize)
{
    var result = {};
    var size = (boardSize && !isNaN(boardSize)) ? boardSize : 19;

    if (!point || isNaN(point.x) || isNaN(point.y))
    {
	return result;
    }

    if (point.x < 0 || point.x >= size || point.y < 0 || point.y >= size)
    {
	return result;
    }

    result.west = point.x > 0 ? {x: point.x - 1, y: point.y} : null;
    result.north = point.y > 0 ? {x: point.x, y: point.y - 1} : null;
    result.east = point.x < size - 1 ? {x: point.x + 1, y: point.y} : null;
    result.south = point.y < size - 1 ? {x: point.x, y: point.y + 1} : null;

    return result;
}